class LoginController {

  static defaultAction = "login"

  def login = {

  }

  def handleLogin = {
    // find the user name
    def user = UserAccount.findByEmailAndPassword(params.email, params.password)
    if (!user) {
      flash.message = "User not found for email: ${params.email}"
      redirect(action: 'login')
      return
    } else {
      session.user = user
      redirect(uri: '/')
    }
  }

  def logout = {
    session.user = null
    session.invalidate()
    redirect(uri: '/')
  }

}
